log using Figure_2, replace
qui{
/**********************/
/*Clean and set memory*/
/**********************/
clear all
set matsize 5000
set more off

/******************/
/*Install programs*/
/******************/

/*********************/
/*Sets base directory*/
/*********************/
global project "D:\IMF_INE_2_2021"  /* Set base directory                         */

/***************************************/
/*Analysis of propensity to participate in an IMF program*/
/***************************************/
use "$project/imf_ehii_code.dta"
xtset ccode1 year
gen high=.
replace high=1 if cname=="Andorra"
replace high=1 if cname=="Antigua and Barbuda"
replace high=1 if cname=="Aruba"
replace high=1 if cname=="Australia"
replace high=1 if cname=="Austria"
replace high=1 if cname=="Bahamas, The"
replace high=1 if cname=="Bahrain"
replace high=1 if cname=="Barbados"
replace high=1 if cname=="Belgium"
replace high=1 if cname=="Bermuda"
replace high=1 if cname=="British Virgin Islands"
replace high=1 if cname=="Brunei Darussalam"
replace high=1 if cname=="Canada"
replace high=1 if cname=="Cayman Islands"
replace high=1 if cname=="Channel Islands"
replace high=1 if cname=="Chile"
replace high=1 if cname=="Croatia"
replace high=1 if cname=="Curacao"
replace high=1 if cname=="Cyprus"
replace high=1 if cname=="Czech Republic"
replace high=1 if cname=="Denmark"
replace high=1 if cname=="Estonia"
replace high=1 if cname=="Faroe Islands"
replace high=1 if cname=="Finland"
replace high=1 if cname=="France"
replace high=1 if cname=="French Polynesia"
replace high=1 if cname=="Germany"
replace high=1 if cname=="Gibraltar"
replace high=1 if cname=="Greece"
replace high=1 if cname=="Greenland"
replace high=1 if cname=="Guam"
replace high=1 if cname=="Hong Kong SAR, China"
replace high=1 if cname=="Hungary"
replace high=1 if cname=="Iceland"
replace high=1 if cname=="Ireland"
replace high=1 if cname=="Isle of Man"
replace high=1 if cname=="Israel"
replace high=1 if cname=="Italy"
replace high=1 if cname=="Japan"
replace high=1 if cname=="Korea, Rep."
replace high=1 if cname=="Kuwait"
replace high=1 if cname=="Latvia"
replace high=1 if cname=="Liechtenstein"
replace high=1 if cname=="Lithuania"
replace high=1 if cname=="Luxembourg"
replace high=1 if cname=="Macao SAR, China"
replace high=1 if cname=="Malta"
replace high=1 if cname=="Monaco"
replace high=1 if cname=="Nauru"
replace high=1 if cname=="Netherlands"
replace high=1 if cname=="New Caledonia"
replace high=1 if cname=="New Zealand"
replace high=1 if cname=="Northern Mariana Islands"
replace high=1 if cname=="Norway"
replace high=1 if cname=="Oman"
replace high=1 if cname=="Palau"
replace high=1 if cname=="Poland"
replace high=1 if cname=="Portugal"
replace high=1 if cname=="Puerto Rico"
replace high=1 if cname=="Qatar"
replace high=1 if cname=="San Marino"
replace high=1 if cname=="Saudi Arabia"
replace high=1 if cname=="Seychelles"
replace high=1 if cname=="Singapore"
replace high=1 if cname=="Sint Maarten (Dutch part)"
replace high=1 if cname=="Slovak Republic"
replace high=1 if cname=="Slovenia"
replace high=1 if cname=="Spain"
replace high=1 if cname=="St. Kitts and Nevis"
replace high=1 if cname=="St. Martin (French part)"
replace high=1 if cname=="Sweden"
replace high=1 if cname=="Switzerland"
replace high=1 if cname=="Trinidad and Tobago"
replace high=1 if cname=="Turks and Caicos Islands"
replace high=1 if cname=="United Arab Emirates"
replace high=1 if cname=="United Kingdom"
replace high=1 if cname=="United States"
replace high=1 if cname=="Uruguay"
replace high=1 if cname=="Virgin Islands (U.S.)"

drop if high==1
rename ehii y 

gen dy=d.y

gen timfprogram=.
replace timfprogram=1 if imf_all==1&l.imf_all==0
replace timfprogram=0 if imf_all==0&l.imf_all==0  
}
/* Estimates */
qui{
probit timfprogram l.y i.year, r cluster(ccode1)
margins,  dydx(L1.y) post
nlcom (inceffect: _b[L1.y]), post

probit timfprogram l.dy l2.y i.year, r
margins,  dydx(L1.dy L2.y) post
nlcom (dif1: _b[L1.dy]) (inceffect: _b[L2.y]), post

probit timfprogram l.dy l2.dy l3.y i.year, r
margins,  dydx(L1.dy L2.dy L3.y) post
nlcom (dif1: _b[L1.dy]) (dif2: _b[L2.dy]) (inceffect: _b[L3.y]), post

probit timfprogram l.dy l2.dy l3.dy l4.y i.year, r
predict _pscore1 if e(sample), pr 
margins,  dydx(L1.dy L2.dy L3.dy L4.y) post
nlcom (dif1: _b[L1.dy]) (dif2: _b[L2.dy]) (dif3: _b[L3.dy]) (inceffect: _b[L4.y]), post

probit timfprogram l.dy l2.dy l3.dy  i.year, r
predict _pscore2 if e(sample), pr 
margins,  dydx(L1.dy L2.dy L3.dy) post
nlcom (dif1: _b[L1.dy]) (dif2: _b[L2.dy]) (dif3: _b[L3.dy]) , post

}

/*Analysis of pscore*/
sum _pscore1 _pscore2
cor _pscore1 _pscore2

/*Overlap figures*/
kdensity _pscore1 if timfprogram==1, generate(x_treat1 prob_treat1) nograph
kdensity _pscore1 if timfprogram==0, generate(x_control1 prob_control1) nograph

twoway (line prob_treat1 x_treat1, lcolor(black) lpattern(solid)) ///
       (line prob_control1 x_control1, lcolor(gray) lpattern(dash)) ///
       , ytitle(Estimated density) xtitle(Propensity to participate in an IMF program) legend(on order(1 "Propensity to participate among participant countries" 2 "Propensity to participate among non-participant countries" ) rows(2) region(fcolor(white) margin(zero) lcolor(white)) bmargin(zero)) ///
	   graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph save "$project/FIGURE2/Figure_2.gph",  replace /*Plots and saves figure 2*/


log close

translate Figure_2.smcl Figure_2.pdf
